package com.kit.data.kitopeso.tools;


import com.otaliastudios.cameraview.CameraView;
import com.otaliastudios.cameraview.controls.Facing;
import com.otaliastudios.cameraview.controls.PictureFormat;

public class Camera2Helper {


    private CameraView cameraView;


    public Camera2Helper(CameraView cameraView) {
        this.cameraView = cameraView;
        cameraView.setPictureFormat(PictureFormat.JPEG);
    }

    public void openCamera(boolean isBack) {
        if (cameraView != null) {
            if (isBack) {
                cameraView.setFacing(Facing.BACK);
            } else {
                cameraView.setFacing(Facing.FRONT);
            }
            cameraView.open();
        }
    }

    public void startPreview() {
        if (cameraView != null) {
            cameraView.setPreviewFrameRate(0F);
        }
    }


    public void takePicture() {
        if (cameraView != null) {
            cameraView.takePicture();
        }
    }



    public void closeCamera() {
        if (cameraView != null) {
            cameraView.close();
        }
    }


}